package com.ssy.lingxi.purchase.serviceimpl.feign;

import com.ssy.lingxi.message.api.feign.SystemMessageControllerFeign;
import com.ssy.lingxi.message.api.vo.request.SystemMessageRequest;
import com.ssy.lingxi.purchase.entity.bidding.Bidding;
import com.ssy.lingxi.purchase.entity.onlinebidding.OnLineBidding;
import com.ssy.lingxi.purchase.service.feign.IPurchaseMessageFeign;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;

/**
 * 采购消息内部接口
 * @author yzc
 * @version 2.0.0
 * @date 2021/7/12
 */
@Slf4j
@Service
public class PurchaseMessageFeignImpl implements IPurchaseMessageFeign {

    @Resource
    SystemMessageControllerFeign systemMessageControllerFeign;

    @Async
    @Override
    public void sendSystemMessageBidding(Bidding bidding, String name){
        try {
            SystemMessageRequest request = new SystemMessageRequest();
            request.setMemberId(bidding.getCreateMemberId());
            request.setRoleId(bidding.getCreateMemberRoleId());
            request.setMessageNotice(name);
            request.setParams(Arrays.asList(bidding.getBiddingNo(), bidding.getDetails()));
            systemMessageControllerFeign.sendSystemMessage(request);
        } catch (Exception e) {
            log.error("发送竞价单通知消息异常", e);
        }
    }

    @Async
    @Override
    public void sendSystemMessageOnLineBidding(OnLineBidding onLineBidding, String name) {
        try {
            SystemMessageRequest request = new SystemMessageRequest();
            Bidding bidding = onLineBidding.getBidding();
            request.setMemberId(bidding.getCreateMemberId());
            request.setRoleId(bidding.getCreateMemberRoleId());
            request.setMessageNotice(name);
            request.setParams(Arrays.asList(bidding.getBiddingNo(), bidding.getDetails()));
            systemMessageControllerFeign.sendSystemMessage(request);
        } catch (Exception e) {
            log.error("发送竞价单通知消息异常", e);
        }
    }
}
